package com.angel.kuaidi.view;

import com.angel.kuaidi.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class BaseLayout extends RelativeLayout {

	private TextView tv_header;
	public View header_bar;
	private LinearLayout ll_header_left;
	private TextView tv_header_left;
	private LinearLayout ll_header_right;
	private TextView tv_header_right;
	private Context mContext;

	public BaseLayout(Context context, int layoutResourceId) {
		super(context);
		mContext = context;
		LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		header_bar = layoutInflater.inflate(R.layout.header, null);
		header_bar.setId(R.id.header_bar);
		tv_header = (TextView) header_bar.findViewById(R.id.tv_header_middle);

		ll_header_left = (LinearLayout) header_bar.findViewById(R.id.ll_header_left);
		tv_header_left = (TextView) header_bar.findViewById(R.id.tv_header_left);
		ll_header_right = (LinearLayout) header_bar.findViewById(R.id.ll_header_right);
		tv_header_right = (TextView) header_bar.findViewById(R.id.tv_header_right);

		RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		addView(header_bar, params);
		View view = layoutInflater.inflate(layoutResourceId, null);
		RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		params2.addRule(RelativeLayout.BELOW, R.id.header_bar);
		addView(view, params2);
	}

	/**
	 * 设置左边按钮
	 */
	public void setLeftBtnText(String text) {

		if (text != null && !"".equals(text) && ll_header_left != null) {
			tv_header_left.setText(text);
			ll_header_left.setVisibility(View.VISIBLE);
			ll_header_left.setOnClickListener((OnClickListener) mContext);
		}
	}

	/**
	 * 设置右边按钮
	 */
	public void setRightBtnText(String text) {

		if (text != null && !"".equals(text) && ll_header_right != null) {
			tv_header_right.setText(text);
			ll_header_right.setVisibility(View.VISIBLE);
			ll_header_right.setOnClickListener((OnClickListener) mContext);
		}
	}

	public void setTitle(String title) {
		if (title != null) {
			tv_header.setVisibility(View.VISIBLE);
			tv_header.setText(title);
		} else {
			tv_header.setVisibility(View.GONE);
		}
	}
}
